//
//  AppBaseRequest.m
//  littleVideoGo
//
//  Created by WeiWei on 2018/8/9.
//  Copyright © 2018年 Liu. All rights reserved.
//

#import "AppBaseRequest.h"

@implementation AppBaseRequest

#pragma mark - 主要方法
+ (void)POSTWithParameters:(NSDictionary *)parameters success:(Success)success failure:(Failure)failure {
    AFHTTPSessionManager *manager = [self manager];
    NSDictionary *requestParameters = [self requestParametersWithParameters:parameters];

    [manager POST:APPBASEURL parameters:requestParameters headers:nil progress:nil success:success failure:failure];
    NSLog(@"\n\n------------------------------RequestDetail------------------------------\ntype: POST\nurl: %@\nparameters: %@\n------------------------------------------------------------\n\n-", APPBASEURL, requestParameters.description);
}

+ (void)GETWithParameters:(NSDictionary *)parameters success:(Success)success failure:(Failure)failure {
    AFHTTPSessionManager *manager = [self manager];
    NSDictionary *requestParameters = [self requestParametersWithParameters:parameters];
    
    [manager GET:APPBASEURL parameters:requestParameters headers:nil progress:nil success:success failure:failure];
    NSLog(@"\n\n------------------------------RequestDetail------------------------------\n类型: GET\n地址: %@\n参数: %@\n------------------------------------------------------------\n\n-", APPBASEURL, requestParameters.description);
}

#pragma mark - 相关方法
+ (AFHTTPSessionManager *)manager {
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
    return manager;
}

+ (NSDictionary *)requestParametersWithParameters:(NSDictionary *)parameters {
    NSMutableDictionary *requestParameters = [NSMutableDictionary dictionaryWithDictionary:parameters];
    requestParameters[@"appid"] = APPID;
    requestParameters[@"timestamp"] = [AppHandyMethods getTimeStamp];
    requestParameters[@"sign"] = [AppHandyMethods getSignWithRequestParameters:requestParameters];
    return requestParameters;
}

@end
